<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/mainTemplate.xhtml">

    <ui:define name="content">
        <h:form id="projectMain">
            <p:layout fullPage="true">

                <p:layoutUnit position="north" size="60">
                    <p:hotkey bind="enter" actionListener="#{searchBean.search}" oncomplete="#{searchBean.redirectToResultPage()}" />

                    <p:menubar>
                            <p:menuitem value="Проекты" url="/view/projects.xhtml" />
                            <p:menuitem value="Заказчики" url="/view/customers.xhtml" icon="ui-icon-arrowreturnthick-1-w" />
                            <p:menuitem value="Материалы" url="/view/materials.xhtml" />
                            <p:menuitem value="Сотрудники" url="/view/employees.xhtml"/>
                            <p:menuitem value="Техника" url="/view/mechanisms.xhtml" />

                    </p:menubar>

                </p:layoutUnit>

                <p:layoutUnit id="left" position="west" size="200"  resizable="true"  header="Проекты"
                              style="text-align:center">
                    <h:form>
                        <p:tree value="#{projectMainBean.projectTree}" var="project" selectionMode="single"
                                selection="#{projectMainBean.selectedTree}"  style="width:170px">
                            <p:ajax event="select" update=":projectMain:projectView,:projectMain:projectProperty"/>

                            <p:treeNode icon="ui-icon-mail-closed">
                                <h:outputText value="#{project}"/>
                            </p:treeNode>

                        </p:tree>
                    </h:form>
                </p:layoutUnit>

                <p:layoutUnit id="centerLayout"  position="center">
                    <p:layout id="bodyLayout">

                        <p:layoutUnit position="north" minSize="200" resizable="true" styleClass="nestedUnit">
                            <p:tabView  value="#{projectMainBean.selectedProject}" var="selectedProject"
                                       orientation="top" widgetVar="projectView" id="projectView">
                                <p:tab  title="#{selectedProject.name}">
                                    <h:panelGrid columns="2">
                                        <h:outputText value="Заказчик: "/>
                                        <h:outputText value="#{projectBean.getCustomer(selectedProject.id)}"/>
                                        <h:outputText value="Срок выполнения: "/>
                                        <h:outputText value="#{projectBean.getProjectEndDate(selectedProject.id)}"/>
                                        <h:outputText value="Стоймость заказа: "/>
                                        <h:outputText value="#{projectBean.getProjectTotal(selectedProject.id)} руб."/>
                                        <h:outputText value="Описание: "/>
                                        <h:outputText value="#{selectedProject.description}"/>
                                    </h:panelGrid>
                                </p:tab>
                            </p:tabView>
                        </p:layoutUnit>
                        <p:layoutUnit position="center" styleClass="nestedUnit">
                            <h:inputHidden value="#{projectMainBean.selectedProject.id}" />
                            <p:tabView orientation="top" widgetVar="projectProperty" id="projectProperty">
                                <p:tab title="Сотрудники">
                                    <p:dataTable id="projectEmployee" var="employee" value="#{projectMainBean.employee}"
                                                 rowKey="#{employee.name}"
                                                 selection="#{employeesBean.selectedEmployee}" selectionMode="single">

                                        <p:column headerText="ФИО">
                                            #{employee.name}
                                        </p:column>

                                        <p:column headerText="Тип зарплаты">
                                            #{employee.salaryType.name}
                                        </p:column>

                                        <p:column headerText="Задолжность" >
                                            #{projectMainBean.getEmployeeDeptByProject(employee.name)} руб.
                                        </p:column>

                                        <p:column headerText="Трудозатраты">
                                            #{projectMainBean.getEmployeeHours(employee.id)}
                                        </p:column>

                                        <f:facet name="footer">
                                            <h:outputText value="Полная задолжность: #{projectMainBean.totalDept} руб."/>
                                        </f:facet>
                                    </p:dataTable>


                                </p:tab>

                                <p:tab title="Техника">
                                    <p:dataTable id="projectMechanism" var="mechanism"
                                                 value="#{projectMainBean.mechanisms}"
                                                 rowKey="#{mechanism.name}"
                                                 selection="#{mechanismsBean.selectedMechanism}" selectionMode="single">

                                        <p:column headerText="Название">
                                            #{mechanism.name}
                                        </p:column>

                                        <p:column headerText="Полное наиминование">
                                            #{mechanism.fullName}
                                        </p:column>

                                        <p:column headerText="Колличество часов" >
                                            #{projectMainBean.getMechanismHours(mechanism.id)}
                                        </p:column>

                                        <p:column headerText="Затраты">
                                            #{projectMainBean.getMechanismCosts(mechanism.id)} руб.
                                        </p:column>

                                    </p:dataTable>

                                </p:tab>

                                <p:tab title="Материалы">
                                    <p:dataTable id="projectMaterials" var="material" value="#{projectMainBean.materials}"
                                                 rowKey="#{material.name}"
                                                 selection="#{employeesBean.selectedEmployee}" selectionMode="single">

                                        <p:column headerText="Наиминование">
                                            #{material.name}
                                        </p:column>

                                        <p:column headerText="Колличестов">
                                            #{projectMainBean.getMaterialQuantity(material.id)}
                                        </p:column>

                                        <p:column headerText="Стоймость">
                                            #{projectMainBean.getMaterialTotal(material.id)} руб.
                                        </p:column>

                                    </p:dataTable>

                                </p:tab>

                                <p:tab title="Оплаты">
                                    <p:dataTable id="projectIncomes" var="income" value="#{projectMainBean.projectIncomes}"
                                                 rowKey="#{income.date}">

                                        <p:column headerText="Заказчик">
                                            #{incomeBean.getIncomeCustomer(income.id)}
                                        </p:column>

                                        <p:column headerText="Дата">
                                            #{income.date}
                                        </p:column>

                                        <p:column headerText="Сумма" >
                                            #{income.total} руб.
                                        </p:column>

                                    </p:dataTable>
                                </p:tab>

                                <p:tab title="Затраты">
                                    <p:dataTable id="projectCosts" var="cost" value="#{projectMainBean.projectCosts}"
                                                 rowKey="#{cost.changeDate}"
                                                 selection="#{costBean.selectedCost}" selectionMode="single">

                                        <p:column headerText="Дата">
                                            #{cost.changeDate}
                                        </p:column>

                                        <p:column headerText="Вид затрат">
                                            #{cost.costsTypes.name}
                                        </p:column>

                                        <p:column headerText="Сумма" >
                                            #{cost.total}  руб.
                                        </p:column>
                                        <p:column headerText="Описание">
                                            #{cost.notes}
                                        </p:column>
                                        <f:facet name="footer">
                                            <h:outputText value="Полная задолжность: #{projectMainBean.totalCosts} руб."/>
                                        </f:facet>
                                    </p:dataTable>
                                </p:tab>
                            </p:tabView>


                        </p:layoutUnit>
                    </p:layout>
                </p:layoutUnit>
            </p:layout>
        </h:form>
    </ui:define>
</ui:composition>